package com.dsx.haha.controller;

import com.dsx.haha.model.entity.Article;
import com.dsx.haha.model.entity.User;
import com.dsx.haha.model.vo.ArticleVo;
import com.dsx.haha.service.ArticleService;
import com.dsx.haha.service.UserService;
import com.dsx.haha.utils.RedPrint;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.jws.WebParam;
import javax.servlet.http.HttpSession;

/**
 * @author dsx
 * @date 2021/3/14 18:06
 * @since JDK1.8
 */
@Controller
@RequestMapping("/article")
public class ArticleController {
    @Reference
    ArticleService articleService;
    @Reference
    UserService userService;
    
    @RequestMapping("/tocreateArticle")
    public String toCreateArticle(String tid, Model model){
        model.addAttribute("tid",tid);
        return "article/createArticle";
    }
    @RequestMapping("/createArt")
    public String createArticle(ArticleVo articleVo, Model model,HttpSession session){
        String userId = userService.getUserId((String) session.getAttribute("username"));
        articleVo.setCreateUserId(userId);
        int i = articleService.addArticle(articleVo);
        if (i>0){
            return "redirect:/tenant/loginsucc";
        }
        model.addAttribute("addfail","添加失败,请重新添加");
        return "article/createArticle";
    }
    
    @RequestMapping("/rmart")
    @ResponseBody
    public String  rmart(ArticleVo articleVo){
        articleService.removeArticle(articleVo);
        return "删除成功！";
    }
}
